package com.woniuxy.java106crm.service.impl;

import com.woniuxy.java106crm.entity.Order;
import com.woniuxy.java106crm.entity.OrderDetail;
import com.woniuxy.java106crm.mapper.OrderMapper;
import com.woniuxy.java106crm.service.OrderService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {
    @Resource
    private OrderMapper orderMapper;

    @Override
    public List<Order> findOrderByCid(String customerid) {
        return orderMapper.findOrderByCid(customerid);
    }

    @Override
    public void deleteById(Integer id) {
        orderMapper.deleteById(id);
    }

    @Transactional
    @Override
    public void batchedDelByIds(String ids) {
        String[] splits = ids.split(",");
        for (String id: splits) {
            orderMapper.deleteById(Integer.valueOf(id));
        }
    }

    @Override
    public boolean updateOrder(Order order) {
        return orderMapper.updateOrder(order);
    }

    @Override
    public List<OrderDetail> findOrderDetail(Integer oid) {
        return orderMapper.findOrderDetail(oid);
    }
}
